package charts.series.pies ;

import string.Utils;
import charts.series.HasTooltip;
import flash.text.TextField;
import flash.text.TextFormat;

class PieLabel extends TextField, implements HasTooltip {
	public var is_over:Bool;
	static var TO_RADIANS: Float = Math.PI / 180;
	
	public function new ( style:Dynamic )
	{
		super();
		this.text = style.label;
		// legend_tf._rotation = 3.6*value.bar_bottom;
		
		var fmt:TextFormat = new TextFormat();
		fmt.color = string.Utils.get_color( style.color );
		fmt.font = "Verdana";
		fmt.size = Reflect.field(style,'font-size');
		fmt.align = flash.text.TextFormatAlign.CENTER;
		this.setTextFormat(fmt);
		this.autoSize = flash.text.TextFieldAutoSize.LEFT;
		
		this.mouseEnabled = false;
	}
	
	public function move_label( rad: Float, x: Float, y: Float, ang: Float ):Bool {
		
		//text field position
		var legend_x: Float = x+rad*Math.cos((ang)*TO_RADIANS);
		var legend_y: Float = y+rad*Math.sin((ang)*TO_RADIANS);
		
		//if legend stands to the right side of the pie
		if(legend_x<x)
			legend_x -= this.width;
				
		//if legend stands on upper half of the pie
		if(legend_y<y)
			legend_y -= this.height;
		
		this.x = legend_x;
		this.y = legend_y;
		
		// does the label fit onto the stage?
		if( (this.x > 0) &&
			(this.y > 0) &&
			(this.y + this.height < this.stage.stageHeight ) &&
			(this.x+this.width<this.stage.stageWidth) )
			return true;
		else
			return false;
	}
	
	public function get_tooltip():String {
		//tr.ace(( cast(this.parent,HasTooltip)).get_tooltip());
		return ( cast(this.parent,HasTooltip)).get_tooltip();
	}
	
	public function get_tip_pos():{x:Int, y:Int} {
		return ( cast(this.parent,HasTooltip)).get_tip_pos();
	}
	
	public function set_tip( b:Bool ):Void {
		return ( cast(this.parent,HasTooltip)).set_tip(b);
	}
	
	public function resize ( sc:ScreenCoords ): Void {
		
	}
}
